package com.example.plugins

import com.example.routes.adminRouting
import com.example.routes.asmrRouting
import com.example.routes.fileRoutes
import com.example.routes.userRouting
import com.example.service.ASMRService
import com.example.service.CollectService
import com.example.service.HistoryService
import com.example.service.UserService
import io.ktor.http.*
import io.ktor.server.application.*
import io.ktor.server.http.content.*
import io.ktor.server.plugins.cors.routing.*
import io.ktor.server.routing.*

fun Application.configureRouting() {
    val asmrService = ASMRService()
    val userService = UserService()
    val historyService = HistoryService()
    val collectService = CollectService()
    routing {
        staticResources("/", "files", "login.html")
//        route("management") {
//            get("login") {
//                call.respond(LocalFileContent(File("src/main/resources/files/login.html")))
//            }
//            get("index") {
//
//            }
//        }
        route("api") {
            install(CORS) {
                allowHost("localhost:8081")
//        anyHost()Multiplatform
                allowHeader(HttpHeaders.ContentType)
                HttpMethod.DefaultMethods.forEach {
                    allowMethod(it)
                }
                allowHeader(HttpHeaders.Authorization)
            }
            fileRoutes()
            userRouting(userService)
            asmrRouting(asmrService, historyService, collectService)
            adminRouting(userService, asmrService)
        }
    }
}
